package woaini.fenger.core.bot.base;

import cn.hutool.core.map.MapBuilder;

import java.util.HashMap;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import woaini.fenger.core.bot.communication.base.BaseBotRequest;
import woaini.fenger.core.bot.enums.BotStatusEnum;
import woaini.fenger.core.bot.enums.ConnectType;
import woaini.fenger.core.bot.event.Messages;
import woaini.fenger.core.bot.event.BaseEvent;
import woaini.fenger.core.bot.id.ID;
import woaini.fenger.core.bot.internal.Internal;

/**
 * IBot适配器
 *
 * @author yefeng {@code @Date} 2023-05-16 16:50:39
 * @see IBotAdapter
 */
@Slf4j
public abstract class IBotAdapter {

  public Bot bot;

  /**
   * @see Internal 原始方法
   */
  public Internal internal;

  public IBotAdapter(Bot bot) {
    this.bot = bot;
  }

  public IBotAdapter(Bot bot, Internal internal) {
    this.bot = bot;
    this.internal = internal;
  }

  /**
   * @param rawString 原始字符串
   * @return {@link BaseEvent } 解码 @MethodName decode
   * @author yefeng {@date 2024-01-18 15:07:11}
   * @since 1.0
   */
  public abstract BaseEvent decode(ConnectType connectType,String rawString);

  protected boolean checkBot() {
    // 发送消息
    if (!this.bot.getStatus().equals(BotStatusEnum.ONLINE)) {
      log.warn("设备已经离线，消息发送失败:{}", this.bot.getSelfId());
      return false;
    }
    return true;
  }

  /**
   * @param userId 用户ID
   * @param message 消息
   * @param autoEscape 自动转义 @MethodName sendPrivateMessage
   * @author yefeng {@date 2024-01-21 10:32:35}
   * @since 1.0
   *     <p>发送私信
   */
  public abstract void sendPrivateMessage(ID userId, Messages message, boolean autoEscape);

  /**
   * @param groupId 组ID
   * @param message 消息
   * @param autoEscape 自动转义 @MethodName sendGroupMsg
   * @author yefeng {@date 2024-01-21 10:32:38}
   * @since 1.0
   *     <p>发送群组消息
   */
  public abstract void sendGroupMsg(ID groupId, Messages message, boolean autoEscape);

  /**
   * @param messageType 消息类型
   * @param userId 用户ID
   * @param groupId 组ID
   * @param messages 消息
   * @param autoEscape 自动转义 @MethodName sendMessage
   * @author yefeng {@date 2024-01-18 18:13:59}
   * @since 1.0
   *     <p>发送消息
   */
  public abstract void sendMessage(
      String messageType, ID userId, ID groupId, Messages messages, boolean autoEscape);
}
